﻿#region Copyright Information
/* +------------------------------------------------+
 * |                    GateShift                   |
 * |================================================|
 * | GateShift is open source software under terms  |
 * | of the GPL License Agreement. All code rights  |
 * | are reserved by the project owner and can be   |
 * | changed or revoked at any time. All artistic   |
 * | works of art (i.e 3D Models, Worlds, ...) used |
 * | in this project fall under the artist terms of |
 * | agreement.                                     |
 * |================================================|
 * |    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT   |
 * |    WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   |
 * | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
 * |    MERCHANTABILITY, FITNESS FOR A PARTICULAR   |
 * | PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
 * | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
 * | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
 * |  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,  |
 * | ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
 * |  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  |
 * |                    SOFTWARE.                   |
 * +------------------------------------------------+
 * | Copyright © 2008-2009 By FastNET Services.     |
 * | All Rights Reserved.                           |
 * +------------------------------------------------+  
 */
#endregion
#region Usings

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;

#endregion

namespace GateShift.Servers.GameServer.LoggingSystem
{
    /// <summary>
    /// Standard class for all logging packets
    /// </summary>
    public class LogMessage
    {
        #region CTor/DTor

        /// <summary>
        /// Initializes LogMessage with default values
        /// </summary>
        public LogMessage()
        {
            Categories = new List<int>();

            AppDomainName = AppDomain.CurrentDomain.FriendlyName;
            ProcessID = Process.GetCurrentProcess().Id.ToString();
            ProcessName = Process.GetCurrentProcess().ProcessName;
            ManagedThreadName = Thread.CurrentThread.Name;
            ThreadID = Thread.CurrentThread.ManagedThreadId.ToString();
            TimeStamp = DateTime.UtcNow;
            ActivityID = Guid.NewGuid();
        }

        /// <summary>
        /// Initializes LogMessage providing default values with a single category
        /// </summary>
        /// <param name="title">Title of the event</param>
        /// <param name="description">Description of the event</param>
        /// <param name="priority">Priority of the event</param>
        /// <param name="eventID">ID for the event type</param>
        /// <param name="severity">Severity of the event</param>
        /// <param name="category">Category of the event</param>
        public LogMessage(string title, string description, int priority, int eventID, TraceEventType severity, int category)
            : this(title, description, priority, eventID, severity)
        {
            Categories.Add(category);
        }

        /// <summary>
        /// Initializes LogMessage providing default values with a single category
        /// </summary>
        /// <param name="title">Title of the event</param>
        /// <param name="description">Description of the event</param>
        /// <param name="priority">Priority of the event</param>
        /// <param name="eventID">ID for the event type</param>
        /// <param name="severity">Severity of the event</param>
        /// <param name="categories">Categories of the event</param>
        public LogMessage(string title, string description, int priority, int eventID, TraceEventType severity, IEnumerable<int> categories)
            : this(title, description, priority, eventID, severity)
        {
            if (categories == null) throw new ArgumentNullException("categories");

            Categories.AddRange(categories);
        }

        /// <summary>
        /// Initializes LogMessage providing default values without categories
        /// </summary>
        /// <param name="title">Title of the event</param>
        /// <param name="description">Description of the event</param>
        /// <param name="priority">Priority of the event</param>
        /// <param name="eventID">ID for the event type</param>
        /// <param name="severity">Severity of the event</param>
        public LogMessage(string title, string description, int priority, int eventID, TraceEventType severity)
            : this()
        {
            if (title == null) throw new ArgumentNullException("title");
            if (description == null) throw new ArgumentNullException("description");

            Title = title;
            Description = description;
            Priority = priority;
            EventID = eventID;
            Severity = severity;
        }

        #endregion

        /// <summary>
        /// Title of the event
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// Description of the event
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Priority of the event (Higher values have a higher priority)
        /// </summary>
        public int Priority { get; set; }

        /// <summary>
        /// Identifier for the event
        /// </summary>
        public int EventID { get; set; }

        /// <summary>
        /// Severity level of the event
        /// </summary>
        public TraceEventType Severity { get; set; }

        /// <summary>
        /// List of categories for the event
        /// </summary>
        public List<int> Categories { get; private set; }

        #region AutoInitialized

        /// <summary>
        /// Unique identifier for the event
        /// </summary>
        public Guid ActivityID { get; set; }

        /// <summary>
        /// Application Domain name where the event occurred
        /// </summary>
        public string AppDomainName { get; set; }

        /// <summary>
        /// Process Identifier of the event
        /// </summary>
        public string ProcessID { get; set; }

        /// <summary>
        /// Process Name of the event
        /// </summary>
        public string ProcessName { get; set; }

        /// <summary>
        /// Thread name the event occurred on
        /// </summary>
        public string ManagedThreadName { get; set; }

        /// <summary>
        /// Thread Identifier the event occurred on
        /// </summary>
        public string ThreadID { get; set; }

        /// <summary>
        /// Time the event occurred
        /// </summary>
        public DateTime TimeStamp { get; set; }

        #endregion

    }
}